package game.ghostleg;

import java.io.Serializable;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;

public class Item implements Serializable {
	private int value;
	private int type;
	// 0 == NULL;
	// 1 == no change
	// 2 == +, val = 1~3
	// 3 == -, val = 1~3
	// 4 == *, val = -100~100%
	
	public static Item RandItem() {
		int type, val;
		type	=(int)(Math.random()*4+1);
		if ( type == 1 )
			val = 0;
		else if ( type == 4 )
			val =(int)(Math.random()*201-100);
		else val =(int)(Math.random()*3+1);
		return new Item(val,type);
	}
	public Item() {
		this.value=this.type=0;
	}
	public Item(Item i) {
		this.value=i.value;
		this.type=i.type;
	}
	public Item(int p_val,int p_type) {
		this.value	= p_val;
		this.type	= p_type;
	}	
	public int getType() { return this.type; }
	public int getValue() { return this.value; }
	public String toString() {
		switch ( this.type ) {
			case 0:
				return "EMPTY ITEM";
			case 1:
				return "0";
			case 2:
				return "+"+Integer.toString(this.value);
			case 3:
				return "-"+Integer.toString(this.value);
			case 4:
				return (this.value>=0?"":"-")+Integer.toString(this.type)+"%";
			default:
				System.out.printf("Error in Item : value=%d type=%d\n", this.value,this.type);
				return String.format("Error in Item : value=%d type=%d\n", this.value,this.type);
		}
	}
	public Paint getPaint() {
		Paint paint = new Paint(); 
		paint.setStyle(Style.FILL);
		paint.setTextSize(24); 
		switch ( this.type ) {
			case 1:
				paint.setColor(Color.WHITE);
				break;
			case 2:
				paint.setColor(Color.BLUE);
				break;
			case 3:
				paint.setColor(Color.RED);
				break;
			case 4:
				if ( this.value > 0 )
					paint.setColor(Color.BLUE);
				else if ( this.value == 0 )
					paint.setColor(Color.WHITE);
				else paint.setColor(Color.RED);
				break;
		}
		return paint;
	}
}